package com.qf.day02;

import java.util.concurrent.TimeUnit;

/**
 *         //JUC 包下 睡觉  ： 手里握着锁
 *         TimeUnit.SECONDS.sleep(4);
 *         //Thread.sleep(3000);
 *
 *         this.wait();//等待 睡觉  手里没有锁   唤醒
 * 手机  资源类
 */
class Phone {

    //发短信
    public static synchronized void sendSMS() throws Exception {
        //JUC 包下 睡觉  ： 手里握着锁
        TimeUnit.SECONDS.sleep(4);
        System.out.println("------sendSMS");
    }

    //发邮件
    public synchronized void sendEmail() throws Exception {
        System.out.println("------sendEmail");
    }

    //聊天
    public void getHello() {
        System.out.println("------getHello");
    }

}

public class Lock_8 {

    public static void main(String[] args) throws Exception {

        Phone phone = new Phone();
        Phone phone2 = new Phone();

        new Thread(() -> {//张三
            try {
                phone.sendSMS();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "AA").start();

       // Thread.sleep(100);

        new Thread(() -> {//李四
            try {
                //phone.sendEmail();
                //phone.getHello();
                phone2.sendEmail();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "BB").start();
    }
}